<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Explain API | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'search-explain.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/search-explain.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/search-explain.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/search-explain.html" rel="nofollow" target="_blank">../en/search-explain.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="search.html">Search APIs</a></span>
»
<span class="breadcrumb-node">Explain API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="search-validate.html">« Validate API</a>
</span>
<span class="next">
<a href="search-profile.html">Profile API »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="search-explain"></a>Explain API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/explain.asciidoc">edit</a>
</h2>
</div></div></div>
<p>Returns information about why a specific document matches (or doesn’t match) a
query.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /twitter/_explain/0
{
      "query" : {
        "match" : { "message" : "elasticsearch" }
      }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/2044.console"></div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="sample-api-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/explain.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">GET /&lt;index&gt;/_explain/&lt;id&gt;</code>
<code class="literal">POST /&lt;index&gt;/_explain/&lt;id&gt;</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="sample-api-desc"></a>Description<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/explain.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The explain API computes a score explanation for a query and a specific
document. This can give useful feedback whether a document matches or
didn’t match a specific query.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="sample-api-path-params"></a>Path parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/explain.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">&lt;id&gt;</code>
</span>
</dt>
<dd>
(Required, integer) Defines the document ID.
</dd>
<dt>
<span class="term">
<code class="literal">&lt;index&gt;</code>
</span>
</dt>
<dd>
<p>(Required, string)
Index names used to limit the request.</p>
<p>Only a single index name can be provided to this parameter.</p>
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="sample-api-query-params"></a>Query parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/explain.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">analyzer</code>
</span>
</dt>
<dd>
(Optional, string) Analyzer to use for the query string.
</dd>
<dt>
<span class="term">
<code class="literal">analyze_wildcard</code>
</span>
</dt>
<dd>
(Optional, boolean) If <code class="literal">true</code>, wildcard and prefix queries are
analyzed. Defaults to <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">default_operator</code>
</span>
</dt>
<dd>
(Optional, string) The default operator for query string query: AND or OR.
Defaults to <code class="literal">OR</code>.
</dd>
<dt>
<span class="term">
<code class="literal">df</code>
</span>
</dt>
<dd>
(Optional, string) Field to use as default where no field prefix is
given in the query string.
</dd>
<dt>
<span class="term">
<code class="literal">lenient</code>
</span>
</dt>
<dd>
(Optional, boolean) If <code class="literal">true</code>, format-based query failures (such as
providing text to a numeric field) will be ignored. Defaults to <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">preference</code>
</span>
</dt>
<dd>
(Optional, string) Specifies the node or shard the operation should be
performed on. Random by default.
</dd>
<dt>
<span class="term">
<code class="literal">q</code>
</span>
</dt>
<dd>
(Optional, string) Query in the Lucene query string syntax.
</dd>
<dt>
<span class="term">
<code class="literal">stored_fields</code>
</span>
</dt>
<dd>
(Optional, string) A comma-separated list of stored fields to return in the
response.
</dd>
<dt>
<span class="term">
<code class="literal">routing</code>
</span>
</dt>
<dd>
(Optional, string)
Custom <a class="xref" href="mapping-routing-field.html" title="_routing field">routing value</a>
used to route operations to a specific shard.
</dd>
<dt>
<span class="term">
<code class="literal">_source</code>
</span>
</dt>
<dd>
(Optional, string) True or false to return the <code class="literal">_source</code> field or not, or a
list of fields to return.
</dd>
<dt>
<span class="term">
<code class="literal">_source_excludes</code>
</span>
</dt>
<dd>
<p>
(Optional, string)
A comma-separated list of <a class="xref" href="mapping-source-field.html" title="_source field">source fields</a> to exclude from
the response.
</p>
<p>You can also use this parameter to exclude fields from the subset specified in
<code class="literal">_source_includes</code> query parameter.</p>
<p>If the <code class="literal">_source</code> parameter is <code class="literal">false</code>, this parameter is ignored.</p>
</dd>
<dt>
<span class="term">
<code class="literal">_source_includes</code>
</span>
</dt>
<dd>
<p>
(Optional, string)
A comma-separated list of <a class="xref" href="mapping-source-field.html" title="_source field">source fields</a> to
include in the response.
</p>
<p>If this parameter is specified, only these source fields are returned. You can
exclude fields from this subset using the <code class="literal">_source_excludes</code> query parameter.</p>
<p>If the <code class="literal">_source</code> parameter is <code class="literal">false</code>, this parameter is ignored.</p>
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="sample-api-request-body"></a>Request body<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/explain.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">query</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="query-dsl.html" title="Query DSL">query object</a>) Defines the search definition using the
<a class="xref" href="query-dsl.html" title="Query DSL">Query DSL</a>.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="sample-api-example"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/explain.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /twitter/_explain/0
{
      "query" : {
        "match" : { "message" : "elasticsearch" }
      }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/2045.console"></div>
<p>The API returns the following response:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
   "_index":"twitter",
   "_type":"_doc",
   "_id":"0",
   "matched":true,
   "explanation":{
      "value":1.6943598,
      "description":"weight(message:elasticsearch in 0) [PerFieldSimilarity], result of:",
      "details":[
         {
            "value":1.6943598,
            "description":"score(freq=1.0), computed as boost * idf * tf from:",
            "details":[
               {
                  "value":2.2,
                  "description":"boost",
                  "details":[]
               },
               {
                  "value":1.3862944,
                  "description":"idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:",
                  "details":[
                     {
                        "value":1,
                        "description":"n, number of documents containing term",
                        "details":[]
                     },
                     {
                        "value":5,
                        "description":"N, total number of documents with field",
                        "details":[]
                     }
                  ]
               },
               {
                  "value":0.5555556,
                  "description":"tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:",
                  "details":[
                     {
                        "value":1.0,
                        "description":"freq, occurrences of term within document",
                        "details":[]
                     },
                     {
                        "value":1.2,
                        "description":"k1, term saturation parameter",
                        "details":[]
                     },
                     {
                        "value":0.75,
                        "description":"b, length normalization parameter",
                        "details":[]
                     },
                     {
                        "value":3.0,
                        "description":"dl, length of field",
                        "details":[]
                     },
                     {
                        "value":5.4,
                        "description":"avgdl, average length of field",
                        "details":[]
                     }
                  ]
               }
            ]
         }
      ]
   }
}</pre>
</div>
<p>There is also a simpler way of specifying the query via the <code class="literal">q</code> parameter. The
specified <code class="literal">q</code> parameter value is then parsed as if the <code class="literal">query_string</code> query was
used. Example usage of the <code class="literal">q</code> parameter in the
explain API:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /twitter/_explain/0?q=message:search</pre>
</div>
<div class="console_widget" data-snippet="snippets/2046.console"></div>
<p>The API returns the same result as the previous request.</p>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="search-validate.html">« Validate API</a>
</span>
<span class="next">
<a href="search-profile.html">Profile API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>